package com.zrj.gulimall.controller;

import com.zrj.gulimall.service.SearchService;
import com.zrj.gulimall.vo.SearchParam;
import com.zrj.gulimall.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhaorujie
 * @version 1.0
 * @Description
 * @date 2021/1/30 16:24
 */
@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索商品
     * @param param
     * @param model
     * @param request
     * @return
     */
    @GetMapping("list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request){
        param.set_queryString(request.getQueryString());
        SearchResult searchResult = searchService.search(param);
        model.addAttribute("result", searchResult);
        return "list";
    }


}
